févr. mars avr.
Previous capture 26 Next capture
2013 2014 2015
1 captures
26 mars 14 - 26 mars 14
sparklines
Close Help

Wave59 Bulletin Board

 
 
  
 Search
  
 Posted Today
  
 Most Active
  
 Help   
 » Home »   » Wave59 Forums »   » Wave59 Scripts »   » qscripting

Pages: 3 of 4:    <  1  2  [3]  4  > 

 View Previous Topic
View Next Topic 

   qscripting

 There are 80 replies to this message.  There are 20 replies on this page.

P: 1/29/2014 1:08:38 PM
j61396c

Member

Total Posts: 411
Last Post: 3/21/2014
Member Since: 12/17/2010

Ken, my good man.

I haven't forgotten your kindness either.   As you know, I'm a bit scatterbrained on walking several paths at once so I don't do extremely well at any of them quickly.

Apologies.   I do intend to play with your code further.   I also enjoy watching the other project.   No, I couldn't do it (yet), but I can see how I could really use such a skillset.

Revisions : 0   |    Posted:  1/29/2014 1:08:38 PM    |    IP:  Recorded    |    Report this post
P: 1/29/2014 4:04:24 PM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004


>The "BY" line of code should read "price" not "bar", to get the correct pixel value for the price.


Of course -- I am my own worst proofreader.


>So, how would we code the slope of line AB ? Define "rise" and "run" in terms of AY, BY, and AX,BX .


slope_m = (Ay-By)/(Bx-Ax)


How's that?


Todd



Revisions : 0   |    Posted:  1/29/2014 4:04:24 PM    |    IP:  Recorded    |    Report this post
P: 1/29/2014 4:47:43 PM
KenC

Member

Total Posts: 815
Last Post: 2/21/2014
Member Since: 1/12/2005

Todd,

That's exactly right for the slope.

Next step is to calculate the slope for the perpendicular to the AB trendline.    (There is a simple formula for this, which you may find with an internet search.)   

Then, using this new slope, we need to draw the perpendicular lines sloping away from the A and B points.    This will form the "end tines" of the pitchfork, just like in your original snapshot of the desired end result.

To prepare for coding how to actually draw these lines, please read the qscript help section on Drawing Object Creation, which explains the use of commands for  "canvas" drawing directly on the chart bitmap.  

As an overview, we need to place our "pen" at a starting point, then code where to "move" the pen to the end of our desired line.  There are additional commands to set the color.

So, once familiar with the "canvas" commands, we can then prepare the code lines to draw the perpendicular lines.   Please tackle this trial code ( don't forget to end each line with a semi-colon ) and then we can go over the details and test the script.

Are you having fun yet ???


Ken Churchill
Wave59 Solution Provider
Montage

Revisions : 0   |    Posted:  1/29/2014 4:47:43 PM    |    IP:  Recorded    |    Report this post
P: 1/31/2014 10:52:02 AM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004

Ken,

I'm stuck here.

The slope of perpendicular lines are negative reciprocals of one another, i.e. given slope 2 the slope of the line perpendicular to this is -1/2. Easy enough. But to draw this line from the given length, it seems you would have to code for (1) canvas_movepen to each of the two (x,y) locations on the original as the starting point, and then (2) canvas_lineto a location on the new perpendicular line in order to draw this line.

If this is correct, I would need to solve for an arbitrary (x,y) point on the perpendicular to draw the line through. Is that right? I don't see how merely specifying a slope relation will do this.

Todd

Revisions : 0   |    Posted:  1/31/2014 10:52:02 AM    |    IP:  Recorded    |    Report this post
P: 1/31/2014 12:24:54 PM
KenC

Member

Total Posts: 815
Last Post: 2/21/2014
Member Since: 1/12/2005

Todd,

You are correct -- there must be a second location ( an end point ) for the perpendicular lines to be drawn.   Knowing the starting point and slope,  ANY  end point will do, so just get the pixel (x value )  for 50 bars into the future & use that in the formula.

If this is totally mud, let me know & I'll post a sample line of code.


Ken Churchill
Wave59 Solution Provider
Montage

Revisions : 0   |    Posted:  1/31/2014 12:24:54 PM    |    IP:  Recorded    |    Report this post
P: 2/1/2014 1:26:57 PM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004

Ken,  I feel I've put in my due diligence on this one, but I'm stumped.

Todd

Revisions : 0   |    Posted:  2/1/2014 1:26:57 PM    |    IP:  Recorded    |    Report this post
P: 2/1/2014 4:58:00 PM
KenC

Member

Total Posts: 815
Last Post: 2/21/2014
Member Since: 1/12/2005

Todd,

The end point of the perpendicular "tine" lines is a bit abstract.  It is the "slope" of the line that is important, so the end point could be just a few bars away, or it could be at the last bar of the chart, or it could be off the chart, as long as the rise/run remains equal to the needed slope.

Load this code into the qscript editor and carefully review the last section.  Be sure to set 2 hotspots in the script properties.

My use of a variable named "span" shows how changing the end point of the perpendicular line can be helpful,  all the while maintaining the correct line slope.   The tricky part was simply solving the slope equation to give the new  "Y" value of the end point.

Let me know what questions you might have, and then try to do the code to draw the second tine, from hotspot 2.



# Todd   example              

# 2 hot spots for initial swing
# hot spot price is snapped to the bar H or L, whichever is nearer
# trend line is drawn from hot spot 1 to hot spot 2
# then draw lines from each hotspot, perpendicular to the trendline

input Lines(".5"),MainColor(red),span(150);

If (barnum==barsback)
   {  
    #  step 1  draw the initial trend line from hot spot A to hot spot B

    # get chart price and bar values of hotspots
       barA = hotspot_to_bar(1)-1;       # set the starting bar for trendline
       barback=barnum_to_offset(barA);
       High1=High[barback];
       Low1=Low[barback];
       price1 = hotspot_to_price(1);
       if( (high1-price1 < price1-low1)) { priceA=high1;  } # snap to bar H/L price
       if( (high1-price1 > price1-low1)) { priceA=low1;   }
       trefA=text(barA-2,priceA,priceA,MainColor,tx_right,10);   # display hot spot price

       barB = hotspot_to_bar(2)-1;       # set the ending bar for trendline
       barback=barnum_to_offset(barB);
       High2=High[barback];
       Low2=Low[barback];
       price2 = hotspot_to_price(2);
       if( (high2-price2 < price2-low2)) { priceB=high2;  } # snap to bar H/L price
       if( (high2-price2 > price2-low2)) { priceB=low2;   }
       trefB=text(barB-2,priceB,priceB,MainColor,tx_right,10);   # display hot spot price

       refAB=trendline(barA,priceA,barB,priceB,MainColor);     # draw swing trend line

       # prepare to draw additional lines using "canvas" plots, for geometric accuracy
       #get pixel values of first hotspot  / snap spot
        x1=bar_to_pixel(barA+1);
        y1=price_to_pixel(priceA);
       #get pixel values of the second hotspot / snap spot
        x2=bar_to_pixel(barB+1);
        y2=price_to_pixel(priceB);

        rise=y1-y2; # get slope of primary trendline, note that the delta y values are inverse to price,
                    # prices go UP from bottom of chart to top of chart, while "y" values go DOWN
                    # as the computer screen coordinates are laid out upper left to lower right increments
        run=x2-x1;

        #print " rise/run =  ", rise/run, "  ",;
        degree=atan2(rise,run);                           
        #print " at angle ",degree;

        # the perpendicular of m1 slope is  m2 = - 1/m1      this is the slope needed to draw lines perpendicular to AB
        newSlope= -(1/(rise/run));
        #print "Perpendicular line slope is ",newslope;

                                                                                                      
       # next step --  draw right angle trend lines from hot spots A and B (and midpoint) to end of chart
       # use the perpendicular slope to draw lines from the A & B points  --  slope= rise/run  from points A & B
       # y2 - y1 = m * (x2 - x1)   using the perp.slope as m, and known x1 & y1 from points A & B
                   # so   calculate the needed rise to make the perp. slope correct from run point
       # y2 = y1 + m(x2-x1)     to get the y2 intercept point for the perp. line
       # e.g. if perp slope =  -1.25  then    y2= y1 + -1.25(x2-x1)
       # to draw Perp. line from X1, think of the "run", (x2-x1), as any "span"
       # so  y2 = y1 + m(span)

       canvas_pencolor(MainColor) ;
       canvas_movepen(x1,y1);    # set the start point at snap 1

       ############################################################################

       xRun= x1+span;     # any value for the run may be used-- larger is better to display lines so try input span 500
                          # to extend run to end of chart, the end pixel value of chart's last plot bar would be needed
       yRise= to_int(y1 - newslope*(span));      # subtract not add since y values are inverted
       canvas_lineto(xRun,yRise);   #print "End point of Perp. Line from point A is ",xRun," , ",yRise;

       ############################################################################

   }

Ken Churchill
Wave59 Solution Provider
Montage

Revisions : 0   |    Posted:  2/1/2014 4:58:00 PM    |    IP:  Recorded    |    Report this post
P: 2/5/2014 6:54:00 PM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004

Ken,

Much thanks for your work and patience. Yes, I'm still here, but it is clear to me right now that I'm going to have to delegate this project mostly to the weekend(s). Time...

So, until then.

Todd

Revisions : 0   |    Posted:  2/5/2014 6:54:00 PM    |    IP:  Recorded    |    Report this post
P: 2/10/2014 8:28:16 PM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004

Ken,



This was pretty straightforward, given your template (my additions in boldface.)

So:

# 2 hot spots for initial swin


# hot spot price is snapped to the bar H or L, whichever is nearer
# trend line is drawn from hot spot 1 to hot spot 2
# then draw lines from each hotspot, perpendicular to the trendline
Input Lines(".5"),MainColor(red),span(150);
If (barnum==barsback)

{
# step 1 draw the initial trend line from hot spot A to hot spot B
# get chart price and bar values of hotspots
barA = hotspot_to_bar(1)-1; # set the starting bar for trendline
barback=barnum_to_offset(barA);
High1=High[barback];
Low1=Low[barback];
price1 = hotspot_to_price(1)
if( (high1-price1 < price1-low1)) { priceA=high1; } # snap to bar H/L price
if( (high1-price1 > price1-low1)) { priceA=low1; }
trefA=text(barA-2,priceA,priceA,MainColor,tx_right,10); # display hot spot price
barB = hotspot_to_bar(2)-1; # set the ending bar for trendline
barback=barnum_to_offset(barB);
High2=High[barback];
Low2=Low[barback];
price2 = hotspot_to_price(2);
if( (high2-price2 < price2-low2)) { priceB=high2; } # snap to bar H/L price
if( (high2-price2 > price2-low2)) { priceB=low2; }
trefB=text(barB-2,priceB,priceB,MainColor,tx_right,10); # display hot spot price
refAB=trendline(barA,priceA,barB,priceB,MainColor); # draw swing trend line

# prepare to draw additional lines using "canvas" plots, for geometric accuracy
#get pixel values of first hotspot / snap spot
x1=bar_to_pixel(barA+1);
y1=price_to_pixel(priceA);
#get pixel values of the second hotspot / snap spot
x2=bar_to_pixel(barB+1);
y2=price_to_pixel(priceB);
rise=y1-y2; # get slope of primary trendline, note that the delta y values are inverse to price,
# prices go UP from bottom of chart to top of chart, while "y" values go DOWN
# as the computer screen coordinates are laid out upper left to lower right increments
run=x2-x1;
#print " rise/run = ", rise/run, " ",;
degree=atan2(rise,run);
#print " at angle ",degree;
# the perpendicular of m1 slope is m2 = - 1/m1 this is the slope needed to draw lines perpendicular to AB
newSlope= -(1/(rise/run));
#print "Perpendicular line slope is ",newslope;

# next step -- draw right angle trend lines from hot spots A and B (and midpoint) to end of chart
# use the perpendicular slope to draw lines from the A & B points -- slope= rise/run from points A & B# y2 - y1 = m * (x2 - x1) using the perp.slope as m, and known x1 & y1 from points A & B
# so calculate the needed rise to make the perp. slope correct from run point
# y2 = y1 + m(x2-x1) to get the y2 intercept point for the perp. line
# e.g. if perp slope = -1.25 then y2= y1 + -1.25(x2-x1)
# to draw Perp. line from X1, think of the "run", (x2-x1), as any "span"
# so y2 = y1 + m(span)
canvas_pencolor(MainColor) ;
canvas_movepen(x1,y1); # set the start point at snap 1



############################################################################

xRun= x1+span; # any value for the run may be used-- larger is better to display lines so try input span 500


# to extend run to end of chart, the end pixel value of chart's last plot bar would be needed



Rise=to_int(y1 - newslope*(span)); # subtract not add since y values are inverted

canvas_lineto(xRun,yRise); #print "End point of Perp. Line from point A is ",xRun," , ",yRise;

canvas_movepen(x2,y2);
xRun= x2+span;

yRise=to_int(y2 - newslope*(span));
canvas_lineto(xRun,yRise);


}

I do have a question about:


 x1=bar_to_pixel(barA+1);


and

x2=bar_to_pixel(barB+1);

Why is the +1 in there?

Next: my original idea was to include inputs for different subdivisions of line AB extending on the perpendicular. This would require the ability to specify new locations on AB from which to extend lines. How would one go about that?

Many thanks, as usual.

Todd





View Revisions : 3   |    Posted:  2/10/2014 8:28:16 PM    |    IP:  Recorded    |    Report this post
P: 2/11/2014 9:45:46 AM
KenC

Member

Total Posts: 815
Last Post: 2/21/2014
Member Since: 1/12/2005

Hi, Todd,

Glad you are finding some time to re-visit this project.

The "+1"  affects the location in the "offset"  statement.  The way qscript handles the hotspot location, it makes a difference in where the trend line gets drawn.   Test the code both ways, pressing the "shift" key after drawing the trend line AB on the chart, and you should be able to see the difference.

To draw additional lines at "mid points" of AB, the "starting point" for the canvas pen must be found.  If 1/2 midpoint is desired, then the relative "y" coordinate  would be .5 * the sum (y1+y2)  and the "x" coordinate is found in the same manner.

The script should draw a line of the same slope as the other perpendiculars, from that mid point canvas starting pen location.   Play with that a bit & let me know how it goes.   





Ken Churchill
Wave59 Solution Provider
Montage

Revisions : 0   |    Posted:  2/11/2014 9:45:46 AM    |    IP:  Recorded    |    Report this post
P: 2/11/2014 1:30:34 PM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004

Hi Ken,


OK, very good, I'll be working on this. In the meantime, more questions:


1. What does the input "lines (".5")" refer to?


2. the code refers to "display hot spot price," but no price appears when charted


3. the original line AB does not appear (?)


4. in the code "yRise=to_int(y1 - newslope*(span));" why did you choose to use the function "to_int" ?


Thanks.


Todd


Revisions : 0   |    Posted:  2/11/2014 1:30:34 PM    |    IP:  Recorded    |    Report this post
P: 2/11/2014 2:26:29 PM
KenC

Member

Total Posts: 815
Last Post: 2/21/2014
Member Since: 1/12/2005



Todd,

The input can be used to display "mid points" if the string is used as a numeric multiplier of the  AB point X & Y values  -- per the example previously shown,    .5*(y1+y2)      could be coded as  ( to_double(lines)*(y1+y2)     To use multiple line settings, the input could be expanded to include other divisions of the AB line, even using a "loop"  to  draw them all sequentially.

The text reference to display the hot spot prices works for me -- be sure you have not missed a semi-colon on any lines.  That may also be why the AB trend line is not displayed.

The function "to_int"  is used to produce an integer value for the  x and y  pixel points when a multiplication is done. The canvas pen can only be moved to integer values of x and y points, so the possibility of a fractional value resulting from multiplying newslope by span must be handled. 

Good questions, and you are making excellent progress with this project

Ken Churchill
Wave59 Solution Provider
Montage

Revisions : 0   |    Posted:  2/11/2014 2:26:29 PM    |    IP:  Recorded    |    Report this post
P: 2/16/2014 11:24:29 AM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004

Ken,





This may call into question my excellent progress.





The task, as I understand it, is to locate the start point x,y pixel values for the new line, and then draw a line extending perpendicular from the midpoint of AB. This is what I came up with:





x3=.5*(y1+x1);  #find relative "x" coordinate pixel values of new location
y3=.5*(y1+y2);  #find relative "y" coordinate pixel values of new location
canvas_movepen(x3,y3);  #move pen to new x,y coordinate on .5 the length of AB
xRun=x3+span;  # x axis run perpendicluar to AB
yRise=to_int(y3-newslope*(span)); # y axis run perpendicular to AB
canvas_lineto(xRun,yRise); #draw line





This will draw a line with the correct slope, but extending .5*AB down from the perpendicluar drawn from the lower hotspot of our original trendline, with the new line beginning where the span of that perpendicular ends on the chart. I am perplexed. Also unclear to me is your suggestion ".5*(y1+y2) could be coded as ( to_double(lines)*(y1+y2)." The W59 help file says the function "to_double" is "really only useful when writing DLLs," so it is not clear to me how or why this should be implemented.


Also, I've never been able to get "display hot spot price" to work, and neither will the original AB line show up on my chart. Just the two perpendiculars. The script was copied from your 2/1/14 post. There are no missing semicolons, and it compiles with no warnings. Any ideas why these show up on your chart and not mine?

Thanks for your input.




Todd





 





 






View Revisions : 1   |    Posted:  2/16/2014 11:24:29 AM    |    IP:  Recorded    |    Report this post
P: 2/17/2014 10:16:21 AM
KenC

Member

Total Posts: 815
Last Post: 2/21/2014
Member Since: 1/12/2005

Todd,

Please email me, or post here, your entire qscript.   I'll look to see what might be the cause for the "text display" not working.

The "to_double" was needed to assure that the "line" string input is properly converted to a double precision numeric value when used for drawing the "mid point"  --  using a string input allows for placing multiple "mid point" values in a single input, then parsing them to get values to use in a loop which draws all the midpoints in a single handler.

Anyway, let's look at the detail of what you have so far.

Thanks,


Ken Churchill
Wave59 Solution Provider
Montage

Revisions : 0   |    Posted:  2/17/2014 10:16:21 AM    |    IP:  Recorded    |    Report this post
P: 2/17/2014 11:01:08 AM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004

Ken,

Here is the script:

 

   

# 2 hot spots for initial swing
# hot spot price is snapped to the bar H or L, whichever is nearer
# trend line is drawn from hot spot 1 to hot spot 2
# then draw lines from each hotspot, perpendicular to the trendline

input Lines(".5"),MainColor(red),span(150);

If (barnum==barsback)
   {                             
    #  step 1  draw the initial trend line from hot spot A to hot spot B

    # get chart price and bar values of hotspots
       barA = hotspot_to_bar(1)-1;       # set the starting bar for trendline
       barback=barnum_to_offset(barA);
       High1=High[barback];
       Low1=Low[barback];
       price1 = hotspot_to_price(1);
       if( (high1-price1 < price1-low1)) { priceA=high1;  } # snap to bar H/L price
       if( (high1-price1 > price1-low1)) { priceA=low1;   }
       trefA=text(barA-2,priceA,priceA,MainColor,tx_right,10);   # display hot spot price

       barB = hotspot_to_bar(2)-1;       # set the ending bar for trendline
       barback=barnum_to_offset(barB);
       High2=High[barback];
       Low2=Low[barback];
       price2 = hotspot_to_price(2);
       if( (high2-price2 < price2-low2)) { priceB=high2;  } # snap to bar H/L price
       if( (high2-price2 > price2-low2)) { priceB=low2;   }
       trefB=text(barB-2,priceB,priceB,MainColor,tx_right,10);   # display hot spot price

       refAB=trendline(barA,priceA,barB,priceB,MainColor);     # draw swing trend line

       # prepare to draw additional lines using "canvas" plots, for geometric accuracy
       #get pixel values of first hotspot  / snap spot
        x1=bar_to_pixel(barA+1);
        y1=price_to_pixel(priceA);
       #get pixel values of the second hotspot / snap spot
        x2=bar_to_pixel(barB+1);
        y2=price_to_pixel(priceB);

        rise=y1-y2; # get slope of primary trendline, note that the delta y values are inverse to price,
                    # prices go UP from bottom of chart to top of chart, while "y" values go DOWN
                    # as the computer screen coordinates are laid out upper left to lower right increments
        run=x2-x1;

        #print " rise/run =  ", rise/run, "  ",;
        degree=atan2(rise,run);
        #print " at angle ",degree;

        # the perpendicular of m1 slope is  m2 = - 1/m1      this is the slope needed to draw lines perpendicular to AB
        newSlope= -(1/(rise/run));
        #print "Perpendicular line slope is ",newslope;


       # next step --  draw right angle trend lines from hot spots A and B (and midpoint) to end of chart
       # use the perpendicular slope to draw lines from the A & B points  --  slope= rise/run  from points A & B
       # y2 - y1 = m * (x2 - x1)   using the perp.slope as m, and known x1 & y1 from points A & B
                   # so   calculate the needed rise to make the perp. slope correct from run point
       # y2 = y1 + m(x2-x1)     to get the y2 intercept point for the perp. line
       # e.g. if perp slope =  -1.25  then    y2= y1 + -1.25(x2-x1)
       # to draw Perp. line from X1, think of the "run", (x2-x1), as any "span"
       # so  y2 = y1 + m(span)

       canvas_pencolor(MainColor) ;
       canvas_movepen(x1,y1); # set the start point at snap 1


       ############################################################################

       xRun= x1+span;     # any value for the run may be used-- larger is better to display lines so try input span 500
                        # to extend run to end of chart, the end pixel value of chart's last plot bar would be needed
       yRise=to_int(y1 - newslope*(span));  # subtract not add since y values are inverted

       canvas_lineto(xRun,yRise);      #print "End point of Perp. Line from point A is ",xRun," , ",yRise;

       canvas_movepen(x2,y2);
       xRun= x2+span;
       yRise=to_int(y2 - newslope*(span));
       canvas_lineto(xRun,yRise);

 

       x3=.25*(y1+x1);  #find relative "x" coordinate
       y3=.25*(y1+y2);  #find relative "y" coordinate
       canvas_movepen(x3,y3);  #move pen to new x,y coordinate on .5 the length of AB
       xRun=x3+span;
       yRise=to_int(y3-newslope*(span));
       canvas_lineto(xRun,yRise);


       }

 

 

Revisions : 0   |    Posted:  2/17/2014 11:01:08 AM    |    IP:  Recorded    |    Report this post
P: 2/17/2014 1:29:52 PM
KenC

Member

Total Posts: 815
Last Post: 2/21/2014
Member Since: 1/12/2005

Todd,

From your script:
 x3=.25*(y1+x1);  #find relative "x" coordinate
 y3=.25*(y1+y2);  #find relative "y" coordinate


Todd  --  do you see an error in either of these lines of code ?

Change the  ".25" to   ".5"  to keep the resulting values "inside" the range of the original 2 points.   If you want to use various values, then we must change the formula to "anchor" from one point, using the "difference" of points 1 and 2.   (The math of   .5*(y1+y2)  does this without an anchor.)  then we can use the input "lines" to simply create an input string to show multiple midpoints or extensions  --  but let's do that later.

Now, for the text labels of the hotspot prices --  your code works fine for me with no changes.  There must be something in the maincolor, or hotspot location that is an issue.  If you want me to look at it,  we can Skype so I can see your screen.

TTYL,


Ken Churchill
Wave59 Solution Provider
Montage

Revisions : 0   |    Posted:  2/17/2014 1:29:52 PM    |    IP:  Recorded    |    Report this post
P: 2/17/2014 3:20:40 PM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004

Hi Ken,

My fault here -- that ".25" was left over from an experiment last night -- I have been using ".5" but must have saved the ".25."

Actually, I'm not all that concerned about not being able to see the text labels right now -- probably would not use these in practice.  I'd much more like to get the perpendicular subdivisions of AB worked out.

Todd

Revisions : 0   |    Posted:  2/17/2014 3:20:40 PM    |    IP:  Recorded    |    Report this post
P: 2/17/2014 4:04:24 PM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004

Yikes, another error...nothing like proofreading:

 

x3=.5*(y1+x1);  #find relative "x" coordinate

should read:

x3=.5*(x1+x2);  #find relative "x" coordinate

 

Now it works. Hah.

 

Todd

Revisions : 0   |    Posted:  2/17/2014 4:04:24 PM    |    IP:  Recorded    |    Report this post
P: 2/17/2014 5:32:39 PM
KenC

Member

Total Posts: 815
Last Post: 2/21/2014
Member Since: 1/12/2005




Todd, 

OK, so let's work on the subdivisions of line AB.

One of the things I like to do, though it's a bit awkward at first glance, is to use a "string" input variable to quickly define multiple variables that will be applied to the chart in a similar manner.   

If the values for subdivisions of line AB are likely to change from time to time, if the drawing of the lines is "hard coded" into the script, as they are now,  then one must alter the script and re-build it to change a line location.   Like changing the subdivision line location from   .5    to   .25.    If more than one subdivision is desired, then multiple lines of code must be used for each line.

A string input variable can be "broken into parts"  by using an array that is "split" into those parts.   Each separate part of the string can be identified and then used as a variable in a loop statement that does a repetitive task  --  like drawing a line of a given slope, once the starting coordinates are known.

In the script we are developing, an input was setup called  "Lines"  --  making it a string by enclosing it in quotes.  If the input for "Lines" is   ".5" then there is one item.  If the input is changed to be    ".25,.5,.75"      then it has 3 items, each one separated by a comma within the string.

Study the qscript help about arrays, using the "split" command.   Then this code should make sense:
#######################################################
 # use a string input to quickly alter the midpoint and extension lines within a loop
       define ARRAY Divisions[];
       split(Divisions,Lines,",");    # set each midpoint line value as an array element  of divisions
#######################################################

Next, let's do a "loop" to actually draw the lines at each division.   Each "item" of the array is drawn when the variable    i    is incremented as the loop completes.

#######################################################
for (i=0 to length(divisions) -1 by 1)
           {  Xmid = x2 - to_int((X2-X1)*to_double(divisions[i]));
              Ymid = to_int((Y1-Y2)*to_double(divisions[i]))+ y2;
              canvas_movepen(Xmid,Ymid);                   # set the start point at midpoint
              xRun= Xmid+span;                                     # any value for the run may be used-- larger is better to display lines
              yRise= to_int(Ymid - newslope*(span));      # subtract not add since y values are inverted
              canvas_lineto(xRun,yRise);
           }
#######################################################

After building the script, the input "lines" can be changed to any ratio you want to see and the script will automatically chart it.  There is no need to add any more lines of code to the script when the number of "items" ( midpoint divisions ) is increased.  The "loop" handles as many lines as you give the input for divisions.

Test it by setting the input to     ".25,.5,.75"       to build interior lines.    "1.5,1.25,.25,.5,.75" will add two external lines.  
To draw lines "below" the original  AB line, try this input setting for lines:      ".25,.5,.75,-1.25,-1.5"    --  a minus sign before the value does the trick.

Have fun with it & let me know if you have questions.




Ken Churchill
Wave59 Solution Provider
Montage

View Revisions : 3   |    Posted:  2/17/2014 5:32:39 PM    |    IP:  Recorded    |    Report this post
P: 2/18/2014 2:40:57 PM
abacaba

Member

Total Posts: 208
Last Post: 2/20/2014
Member Since: 7/18/2004

Ken,

This works well. And, I'm able to follow your steps reasonably.  But, I'm still uncertain about the command "to_double(x)."  QScript help says this "returns a forced double conversion of x."  I've reviewed your post on this from 2/17, but still don't feel I could personally choose a context in which this would be used. What is a forced double conversion, and how does it work here?

Todd

Revisions : 0   |    Posted:  2/18/2014 2:40:57 PM    |    IP:  Recorded    |    Report this post

 Previous Page
Pages: 3 of 4:    <  1  2  [3]  4  > 
Next Page 

Jump to:



Contact Us  |  Back Home  |  Privacy Statement

Ideal BB Version: 0.1.5.4bMessage forum software powered by  the Ideal BB